/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package downloadmanager.downloader;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DownloaderBean {

    private String url;
    private String localFile;
    private RemoteFileInfo remoteInfo;
    private int requestedSegments;
    private Date createdDateTime;
    private SegmentBean[] segments;

    public DownloaderBean() {
    }

    public DownloaderBean(Downloader d) {
        url = d.getURL().toString();
        localFile = d.getLocalFile();
        remoteInfo = d.getRemoteFileInfo();
        requestedSegments = d.getRequestedSegments();
        createdDateTime = d.getCreatedDateTime();
        segments = new SegmentBean[d.getSegments().size()];
        for (int i = 0; i < segments.length; i++) {
            segments[i] = new SegmentBean(d.getSegments().get(i));
        }
    }

    public Downloader toDownloader() {
        List<DownloadSegment> dsegments = new ArrayList<DownloadSegment>();
        for (int i = 0; i < segments.length; i++) {
            dsegments.add(segments[i].toDownloaderSegment());
        }
        URL r = null;
        try {
            r = new URL(url);
        } catch (MalformedURLException ex) {
            Logger.getLogger(DownloaderBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new Downloader(r, localFile, dsegments, remoteInfo, requestedSegments, createdDateTime);

    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @return the LocalFile
     */
    public String getLocalFile() {
        return localFile;
    }

    /**
     * @param LocalFile the LocalFile to set
     */
    public void setLocalFile(String LocalFile) {
        this.localFile = LocalFile;
    }

    /**
     * @return the remoteInfo
     */
    public RemoteFileInfo getRemoteInfo() {
        return remoteInfo;
    }

    /**
     * @param remoteInfo the remoteInfo to set
     */
    public void setRemoteInfo(RemoteFileInfo remoteInfo) {
        this.remoteInfo = remoteInfo;
    }

    /**
     * @return the requestedSegments
     */
    public int getRequestedSegments() {
        return requestedSegments;
    }

    /**
     * @param requestedSegments the requestedSegments to set
     */
    public void setRequestedSegments(int requestedSegments) {
        this.requestedSegments = requestedSegments;
    }

    /**
     * @return the createdDateTime
     */
    public Date getCreatedDateTime() {
        return createdDateTime;
    }

    /**
     * @param createdDateTime the createdDateTime to set
     */
    public void setCreatedDateTime(Date createdDateTime) {
        this.createdDateTime = createdDateTime;
    }

    /**
     * @return the Segments
     */
    public SegmentBean[] getSegments() {
        return segments;
    }

    /**
     * @param Segments the Segments to set
     */
    public void setSegments(SegmentBean[] Segments) {
        this.segments = Segments;
    }
}
